package com.ctvit.breadking.news.task.controller;

import com.ctvit.breadking.news.task.pojo.vo.HttpLogVO;
import com.ctvit.breadking.news.task.pojo.vo.StatVO;
import com.ctvit.breadking.news.task.service.TaskService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("task")
public class TaskController {

    private final TaskService taskService;

    public TaskController(TaskService taskService) {
        this.taskService = taskService;
    }

    @PostMapping("execute/all")
    public boolean execute() {
        return taskService.execute();
    }

    @PostMapping("execute/code")
    public boolean execute(@RequestParam String code) {
        return taskService.execute(code);
    }

    @PostMapping("http/log/delete")
    public boolean delete(@RequestParam String id) {
        return taskService.deleteHttpLog(id);
    }

    @PostMapping("http/log/list")
    public List<HttpLogVO> listHttpLog() {
        return taskService.listHttpLog();
    }

    @PostMapping("http/log/get")
    public HttpLogVO getHttpLog(String id) {
        return taskService.getHttpLog(id);
    }

    @PostMapping("http/log/stat")
    public StatVO statHttpLog(@RequestParam String code) {
        return taskService.statHttpLog(code);
    }

}
